#!/usr/bin/python
import random
import sqlite3
import sys
from log import *
reload(sys)
sys.setdefaultencoding('utf-8')


def sql_cont(METHOD):
	conn = sqlite3.connect('test.db')
	# print "Opened database successfully";
	c = conn.cursor()
	c.execute('''SELECT *
		FROM qm_interface_Testdata 
		WHERE METHOD="{METHOD}";
		'''.format(METHOD=METHOD))
	values = c.fetchall()
	# print "Table created successfully"
	conn.commit()
	conn.close()
	# return values
	for i in values:
		return str(i[1])


def getSkus():
	conn = sqlite3.connect('test.db')
	c = conn.cursor()
	c.execute('''SELECT *
		FROM goods;
		''')
	values = c.fetchall()
	conn.commit()
	conn.close()
	get_sku_mes = values[random.randint(0, len(values)-1)] 
	return get_sku_mes[1]


def getMerchant():
	conn = sqlite3.connect('test.db')
	c = conn.cursor()
	c.execute('''SELECT warehouseCode, ownerCode
		FROM config;
		''')
	values = c.fetchall()
	conn.commit()
	conn.close()
	get_merchant = values[random.randint(0, len(values)-1)] 
	return get_merchant


# @logs(totaltime=False)
def testData(sel):
	conn = sqlite3.connect('test.db')
	c = conn.cursor()
	c.execute('''{sel};
		'''.format(sel=sel))
	values = c.fetchall()
	conn.commit()
	conn.close()
	return values


if __name__ == '__main__':
	# pass
	values=testData("SELECT * FROM goods WHERE itemCode='jittest_006'")
	# values = getSkus()
	# values=getMerchant()
	print values#jittest_001